package com.taobaolite.demo_item;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DemoItemService {
    private final DemoItemRepository demoItemRepository;

    @Autowired
    public DemoItemService(DemoItemRepository repo) {
        this.demoItemRepository = repo;
    }

    public List<DemoItem> getItems() {
        return demoItemRepository.findAll();
    }

    public DemoItem getItem(Long itemId) {
        return demoItemRepository.findById(itemId)
                .orElseThrow(() -> new IllegalStateException("Item with ID " +
                        itemId +
                        " does not exist."));
    }
}
